package com.wing.bill.service;

import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.wing.bill.controller.admin.ReportUtil;
import com.wing.bill.dao.WorkshopReportDao;
import com.wing.cabinet.model.response.CabinetVO;
import com.wing.cabinet.utils.FindDateStatusUtil;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.LocalDateTimeUtils;
import com.wing.user.feign.UserClient;
import com.wing.user.model.response.DepartmentVO;
import com.wing.web.db.config.util.DynamicDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
@Slf4j
public class WorkshopReportServiceImpl implements WorkshopReportService{
    @Autowired
    private UserClient userClient;
    @Autowired
    private WorkshopReportDao workshopReportDao;

    @Override
    public JsonResult materialDataAnalysis(String type, String startTime, String endTime, String click, String code,String mainCabCode) {
        List list = new ArrayList();
        HashMap map1 = new HashMap(){{put("title","缺料告警");put("sign","1");}};
        HashMap map2 = new HashMap(){{put("title","领料品种数（种）");put("sign","2");}};
        HashMap map3 = new HashMap(){{put("title","总领料数量（基础单位）");put("sign","3");}};
        HashMap map4 = new HashMap(){{put("title","总领料金额 （元）");put("sign","4");}};
        if(StringUtils.isNotBlank(type)&&click.equals("0")){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    map2.putAll(workshopReportDao.queryMaterialSKUQuantity(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,null));
                    map3.putAll(workshopReportDao.queryMaterialQuantity(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,null));
                    map4.putAll(workshopReportDao.queryMaterialMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,null));
                }else if(type.equals("1")){ // 周
                    map2.putAll(workshopReportDao.queryMaterialSKUQuantity(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,null));
                    map3.putAll(workshopReportDao.queryMaterialQuantity(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,null));
                    map4.putAll(workshopReportDao.queryMaterialMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,null));
                }else if(type.equals("2")){// 月
                    map2.putAll(workshopReportDao.queryMaterialSKUQuantity(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,null));
                    map3.putAll(workshopReportDao.queryMaterialQuantity(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,null));
                    map4.putAll(workshopReportDao.queryMaterialMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,null));
                }
                map1.putAll(workshopReportDao.queryStockWarnedNumber(null));
            }else {
                if(type.equals("0")){ // 日
                    map2.putAll(workshopReportDao.queryMaterialSKUQuantity(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode));
                    map3.putAll(workshopReportDao.queryMaterialQuantity(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode));
                    map4.putAll(workshopReportDao.queryMaterialMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode));
                }else if(type.equals("1")){ // 周
                    map2.putAll(workshopReportDao.queryMaterialSKUQuantity(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,mainCabCode));
                    map3.putAll(workshopReportDao.queryMaterialQuantity(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,mainCabCode));
                    map4.putAll(workshopReportDao.queryMaterialMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,mainCabCode));
                }else if(type.equals("2")){// 月
                    map2.putAll(workshopReportDao.queryMaterialSKUQuantity(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,mainCabCode));
                    map3.putAll(workshopReportDao.queryMaterialQuantity(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,mainCabCode));
                    map4.putAll(workshopReportDao.queryMaterialMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,mainCabCode));
                }
                map1.putAll(workshopReportDao.queryStockWarnedNumber(mainCabCode));
            }
            list.add(map1);
            list.add(map2);
            list.add(map3);
            list.add(map4);
            return JsonResult.success("查询成功", list);
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)&&click.equals("0")){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isBlank(mainCabCode)){
                map1.putAll(workshopReportDao.queryStockWarnedNumber(null));
                map2.putAll(workshopReportDao.queryMaterialSKUQuantity(start,end,code,null));
                map3.putAll(workshopReportDao.queryMaterialQuantity(start,end,code,null));
                map4.putAll(workshopReportDao.queryMaterialMoney(start,end,code,null));
            }else {
                map1.putAll(workshopReportDao.queryStockWarnedNumber(mainCabCode));
                map2.putAll(workshopReportDao.queryMaterialSKUQuantity(start,end,code,mainCabCode));
                map3.putAll(workshopReportDao.queryMaterialQuantity(start,end,code,mainCabCode));
                map4.putAll(workshopReportDao.queryMaterialMoney(start,end,code,mainCabCode));
            }
            list.add(map1);
            list.add(map2);
            list.add(map3);
            list.add(map4);
            return JsonResult.success("查询成功", list);
        }
        //------------------------------------------------- 头部点击事件按日周月查询start ------------------------------------
        //总缺货告警数
        if(StringUtils.isNotBlank(type)&&click.equals("1")){
            if(StringUtils.isNotBlank(mainCabCode)){
                return JsonResult.success("查询成功",workshopReportDao.queryStockWarnedNumberDetail(mainCabCode));
            }else {
                return JsonResult.success("查询成功",workshopReportDao.queryStockWarnedNumberDetail(null));
            }
        }
        //总领料SKU数（个）
        if(StringUtils.isNotBlank(type)&&click.equals("2")){
            if(StringUtils.isNotBlank(mainCabCode)){
                if(type.equals("0")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialSKUQuantityDetail(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode));
                }else if(type.equals("1")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialSKUQuantityDetail(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,mainCabCode));
                }else if(type.equals("2")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialSKUQuantityDetail(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,mainCabCode));
                }
            }else {
                if(type.equals("0")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialSKUQuantityDetail(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,null));
                }else if(type.equals("1")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialSKUQuantityDetail(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,null));
                }else if(type.equals("2")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialSKUQuantityDetail(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,null));
                }
            }
        }
        //总消耗物料数量（个）  总消耗物料金额 （元）
        if(StringUtils.isNotBlank(type)&&(click.equals("3")||click.equals("4"))){
            if(StringUtils.isNotBlank(mainCabCode)){
                if(type.equals("0")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialDetail(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode));
                }else if(type.equals("1")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialDetail(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,mainCabCode));
                }else if(type.equals("2")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialDetail(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,mainCabCode));
                }
            }else {
                if(type.equals("0")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialDetail(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,null));
                }else if(type.equals("1")){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialDetail(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,null));
                }else if(type.equals("2")){
                    List<HashMap> mapList = workshopReportDao.queryMaterialDetail(FindDateStatusUtil.dateUtil().get(0), FindDateStatusUtil.dateUtil().get(1), code, null);
                    for(HashMap item : mapList){
                        if(item.get("departmentId") != null){
                            String departmentId = (String) item.get("departmentId");
                            if(StringUtils.isNotBlank(departmentId)){
                                JsonResult<DepartmentVO> jsonResult = userClient.getDepartmentVOById(Long.valueOf(departmentId));
                               if(jsonResult.getData().getId() != null){
                                   item.put("costCenter",jsonResult.getData().getCostCenter());
                               }else{
                                   item.put("costCenter","");
                               }
                            }
                        }
                    }
                    return JsonResult.success("查询成功",mapList);
                }
            }
        }
        //------------------------------------------------- 头部点击事件按日周月查询end ------------------------------------
        //------------------------------------------------- 头部点击事件按时间区间查询start ------------------------------------
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(click.equals("1")){ ////总缺货告警数
                if(StringUtils.isNotBlank(mainCabCode)){
                    return JsonResult.success("查询成功",workshopReportDao.queryStockWarnedNumberDetail(mainCabCode));
                }else {
                    return JsonResult.success("查询成功",workshopReportDao.queryStockWarnedNumberDetail(null));
                }
            }else if(click.equals("2")){ //总领料SKU数（个）
                if(StringUtils.isNotBlank(mainCabCode)){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialSKUQuantityDetail(start,end,code,mainCabCode));
                }else {
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialSKUQuantityDetail(start,end,code,null));
                }
            }else if(click.equals("3") || click.equals("4")){//总消耗物料数量（个）  总消耗物料金额 （元）
                if(StringUtils.isNotBlank(mainCabCode)){
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialDetail(start,end,code,mainCabCode));
                }else {
                    return JsonResult.success("查询成功",workshopReportDao.queryMaterialDetail(start,end,code,null));
                }
            }
        }
        return JsonResult.fail("查询失败");
    }

    @Override
    public JsonResult findMaterialRequisitionTrend(String param, String enterpriseCode, String mainCabCode) {
        HashMap hm = new HashMap();
        hm.put("title","领料趋势变化图");
        List list = new ArrayList();
        if(StringUtils.isNotBlank(mainCabCode)){
            list.addAll(workshopReportDao.queryMaterialRequisitionTrend(param,enterpriseCode,mainCabCode));
            hm.put("avg",workshopReportDao.queryMaterialRequisitionTrendAvg(param,enterpriseCode,mainCabCode));
        }else {
            list.addAll(workshopReportDao.queryMaterialRequisitionTrend(param,enterpriseCode,null));
            hm.put("avg",workshopReportDao.queryMaterialRequisitionTrendAvg(param,enterpriseCode,null));
        }
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findMaterialTimeComparison(String type, String startTime, String endTime, String code, String mainCabCode,String param) {
        HashMap hm = new HashMap();
        hm.put("title","领料时间对比图");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")) { // 日
                    list.addAll(workshopReportDao.findMaterialTimeComparisonByDay(code,null,param));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.findMaterialTimeComparisonByWeek(code,null,param));
                }else if(type.equals("2")) { // 月
                    list.addAll(workshopReportDao.findMaterialTimeComparisonByMonth(code,null,param));
                }
            }else {
                if(type.equals("0")) { // 日
                    list.addAll(workshopReportDao.findMaterialTimeComparisonByDay(code,mainCabCode,param));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.findMaterialTimeComparisonByWeek(code,mainCabCode,param));
                }else if(type.equals("2")) { // 月
                    list.addAll(workshopReportDao.findMaterialTimeComparisonByMonth(code,mainCabCode,param));
                }
            }
        }

        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.findFixedDateMaterialTimeComparison(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.findFixedDateMaterialTimeComparison(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findEquipmentMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","设备领料对比图（TOP10）");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryEquipmentMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryEquipmentMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryEquipmentMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryEquipmentMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryEquipmentMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryEquipmentMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.queryEquipmentMaterialComparison(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.queryEquipmentMaterialComparison(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findPersonnelMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        String databaseUser = DynamicDataSource.USER_PREFIX;
        if (StringUtils.isNotBlank(DynamicDataSource.name.get())) {
            databaseUser = databaseUser + "-" + DynamicDataSource.name.get();
        }

        HashMap hm = new HashMap();
        hm.put("title","人员领料对比图（TOP10)");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryPersonnelMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null,databaseUser));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryPersonnelMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null,databaseUser));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryPersonnelMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null,databaseUser));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryPersonnelMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode,databaseUser));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryPersonnelMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode,databaseUser));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryPersonnelMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode,databaseUser));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.queryPersonnelMaterialComparison(start,end,code,param,mainCabCode,databaseUser));
                hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.queryPersonnelMaterialComparison(start,end,code,param,null,databaseUser));
                hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findWorkOrderMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","工单领料对比图（TOP10)");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryWorkOrderMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryWorkOrderMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryWorkOrderMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryWorkOrderMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryWorkOrderMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryWorkOrderMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.queryWorkOrderMaterialComparison(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.queryWorkOrderMaterialComparison(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findWorkshopMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","车间领料对比图");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryWorkshopMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryWorkshopMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryWorkshopMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryWorkshopMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryWorkshopMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryWorkshopMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.queryWorkshopMaterialComparison(start,end,code,param,mainCabCode));
                hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.queryWorkshopMaterialComparison(start,end,code,param,null));
                hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findSupplierMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","供应商物料消耗对比图");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.querySupplierMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.querySupplierMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.querySupplierMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.querySupplierMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.querySupplierMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.querySupplierMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.querySupplierMaterialComparison(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.querySupplierMaterialComparison(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findProductMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","领新物料占比排序");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryProductMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryProductMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryProductMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryProductMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryProductMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryProductMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.queryProductMaterialComparison(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.queryProductMaterialComparison(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findBrandMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","领料品牌对比图");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryBrandMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryBrandMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryBrandMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryBrandMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryBrandMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryBrandMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.queryBrandMaterialComparison(start,end,code,param,mainCabCode));
                hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.queryBrandMaterialComparison(start,end,code,param,null));
                hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findCabinetMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","物料消耗智能柜对比图");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }

        List<String> codeList = new ArrayList<>();
        if (StringUtils.isNotBlank(mainCabCode)){
            List<CabinetVO> auxiliaryCabinetList = workshopReportDao.getAuxiliaryCabinet(mainCabCode);
            if (CollectionUtils.isEmpty(auxiliaryCabinetList)){
                log.info("未查询到副柜信息,主柜编号："+mainCabCode);
//                return JsonResult.fail("物料消耗智能柜对比图:主柜下未查询到副柜信息");
            }else {
                for (CabinetVO cabinetVo : auxiliaryCabinetList) {
                    codeList.add(cabinetVo.getCode());
                }
            }
        }

        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryCabinetMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null,codeList));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryCabinetMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null,codeList));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryCabinetMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null,codeList));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryCabinetMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode,codeList));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryCabinetMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode,codeList));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryCabinetMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode,codeList));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.queryCabinetMaterialComparison(start,end,code,param,mainCabCode,codeList));
            }else {
                list.addAll(workshopReportDao.queryCabinetMaterialComparison(start,end,code,param,null,codeList));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findCategoryMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","领料物料分类对比图");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }
        if(StringUtils.isNotBlank(type)){
            if(StringUtils.isBlank(mainCabCode)){
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryCategoryMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,null));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryCategoryMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,null));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryCategoryMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,null));
                }
            }else {
                if(type.equals("0")){ // 日
                    list.addAll(workshopReportDao.queryCategoryMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("1")){ // 周
                    list.addAll(workshopReportDao.queryCategoryMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                }else if(type.equals("2")){ // 月
                    list.addAll(workshopReportDao.queryCategoryMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                    hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                }
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(StringUtils.isNotBlank(mainCabCode)){
                list.addAll(workshopReportDao.queryCategoryMaterialComparison(start,end,code,param,mainCabCode));
                hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(start,end,code,param,mainCabCode));
            }else {
                list.addAll(workshopReportDao.queryCategoryMaterialComparison(start,end,code,param,null));
                hm.put("sum",workshopReportDao.queryMaterialSumQuantityOrMoney(start,end,code,param,null));
            }
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }


    LocalDateTime startWeekDateTime = null;
    LocalDateTime endWeekDateTime = null;
    LocalDateTime startMonthDateTime = null;
    LocalDateTime endMonthDateTime = null;

    /**
     * 根据类型获取不同时间段时间
     * @param dateType
     */
    public void dateTimeByDateType(String dateType){
        if (dateType.equals("before")){//往前推一周/一月
            startWeekDateTime = FindDateStatusUtil.weekUtil().get(0);
            endWeekDateTime = FindDateStatusUtil.weekUtil().get(1);

            startMonthDateTime = FindDateStatusUtil.dateUtil().get(0);
            endMonthDateTime = FindDateStatusUtil.dateUtil().get(1);
        } else if (dateType.equals("current")) {//当周、当月
            startWeekDateTime = ReportUtil.thisWeekUtil().get(0);
            endWeekDateTime = ReportUtil.thisWeekUtil().get(1);

            startMonthDateTime = ReportUtil.monthUtil().get(0);
            endMonthDateTime = ReportUtil.monthUtil().get(1);
        }
    }

    @Override
    public JsonResult findAbnormalStatisticsByDay( String code, String param) {
        HashMap hm = new HashMap();
        hm.put("title","异常统计(按天)");
        List list = new ArrayList();

        list.addAll(workshopReportDao.queryAbnormalStatisticsByDay(code, param));
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findAbnormalStatistics(String type, String dateType, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","异常统计");
        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryAbnormalStatistics(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryAbnormalStatistics(startWeekDateTime,endWeekDateTime,code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryAbnormalStatistics(startMonthDateTime,endMonthDateTime,code,param,mainCabCode));
            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryAbnormalStatistics(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findAbnormalMaterialComparison(String type, String dateType, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","异常物料排名");
        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryAbnormalMaterial(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryAbnormalCauseAnalysisTotal(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryAbnormalMaterial(startWeekDateTime,endWeekDateTime,code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryAbnormalCauseAnalysisTotal(startWeekDateTime,endWeekDateTime,code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryAbnormalMaterial(startMonthDateTime,endMonthDateTime,code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryAbnormalCauseAnalysisTotal(startMonthDateTime,endMonthDateTime,code,param,mainCabCode));
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryAbnormalMaterial(start,end,code,param,mainCabCode));
            hm.put("totalSum",workshopReportDao.queryAbnormalCauseAnalysisTotal(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }
    @Override
    public JsonResult findAbnormalRegistrationComparison(String type,String dateType, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","异常登记人员对比图");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryAbnormalRegistrationComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryAbnormalRegistrationComparison(startWeekDateTime,endWeekDateTime,code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryAbnormalRegistrationComparison(startMonthDateTime,endMonthDateTime,code,param,mainCabCode));
            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryAbnormalRegistrationComparison(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findAbnormalCauseAnalysis(String type,String dateType, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","异常原因占比分析");
        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryAbnormalCauseAnalysis(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryAbnormalCauseAnalysisTotal(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryAbnormalCauseAnalysis(startWeekDateTime,endWeekDateTime,code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryAbnormalCauseAnalysisTotal(startWeekDateTime,endWeekDateTime,code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryAbnormalCauseAnalysis(startMonthDateTime,endMonthDateTime,code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryAbnormalCauseAnalysisTotal(startMonthDateTime,endMonthDateTime,code,param,mainCabCode));
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryAbnormalCauseAnalysis(start,end,code,param,mainCabCode));
            hm.put("totalSum",workshopReportDao.queryAbnormalCauseAnalysisTotal(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }


    @Override
    public JsonResult findGetNewMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","领新柜物料占比");
        List list = new ArrayList();

        if(StringUtils.isNotBlank(type)){
            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryGetNewMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryGetNewMaterialComparisonTotal(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryGetNewMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryGetNewMaterialComparisonTotal(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryGetNewMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryGetNewMaterialComparisonTotal(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryGetNewMaterialComparison(start,end,code,param,mainCabCode));
            hm.put("totalSum",workshopReportDao.queryGetNewMaterialComparisonTotal(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findReturnedMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","未归还物料占比");
        List list = new ArrayList();

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryReturnedMaterialComparison(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryReturnedMaterialComparisonTotal(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryReturnedMaterialComparison(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryReturnedMaterialComparisonTotal(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryReturnedMaterialComparison(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryReturnedMaterialComparisonTotal(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
            }
        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryReturnedMaterialComparison(start,end,code,param,mainCabCode));
            hm.put("totalSum",workshopReportDao.queryReturnedMaterialComparisonTotal(start,end,code,param,mainCabCode));
        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findTSMaterialComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","暂存物料占比");
        List list = new ArrayList();

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryTSMC(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryTSMCTotal(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryTSMCTotalOne(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryTSMC(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryTSMCTotal(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryTSMCTotalOne(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryTSMC(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryTSMCTotal(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryTSMCTotalOne(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryTSMC(start,end,code,param,mainCabCode));
            hm.put("totalSum",workshopReportDao.queryTSMCTotal(start,end,code,param,mainCabCode));
            hm.put("totalSumOne",workshopReportDao.queryTSMCTotalOne(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findPurchaseMaterialModelComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","采购物料规格型号占比");
        List list = new ArrayList();

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryPMMC(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryPMMCTotal(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryPMMCTotalOne(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryPMMC(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryPMMCTotal(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryPMMCTotalOne(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryPMMC(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                hm.put("totalSum",workshopReportDao.queryPMMCTotal(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryPMMCTotalOne(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryPMMC(start,end,code,param,mainCabCode));
            hm.put("totalSum",workshopReportDao.queryPMMCTotal(start,end,code,param,mainCabCode));
            hm.put("totalSumOne",workshopReportDao.queryPMMCTotalOne(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findPurchaseMaterialSupplierComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","采购物料供应商占比分析");
        List list = new ArrayList();
        if(param.equals("qua")){
            hm.put("unit","支");
        }else {
            hm.put("unit","元");
        }

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryPMSC(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryPMSC(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryPMSC(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryPMSC(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findTSMaterialBrandComparison(String type, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","暂存物料品牌占比分析");
        List list = new ArrayList();

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryTSMBC(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryTSMBCTotalOne(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryTSMBC(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryTSMBCTotalOne(FindDateStatusUtil.weekUtil().get(0),FindDateStatusUtil.weekUtil().get(1),code,param,mainCabCode));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryTSMBC(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
                hm.put("totalSumOne",workshopReportDao.queryTSMBCTotalOne(FindDateStatusUtil.dateUtil().get(0),FindDateStatusUtil.dateUtil().get(1),code,param,mainCabCode));
            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryTSMBC(start,end,code,param,mainCabCode));
            hm.put("totalSumOne",workshopReportDao.queryTSMBCTotalOne(start,end,code,param,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);

    }

    @Override
    public JsonResult findCheckedResultStatisticsByDay(String code, String param, Integer businessTypeChecked) {
        HashMap hm = new HashMap();
        switch (businessTypeChecked){
            case 2:
                hm.put("title","报修统计(按天)");
                break;
            case 3:
                hm.put("title","报废统计(按天)");
                break;
            default:
                break;
        }

        List list = new ArrayList();
        list.addAll(workshopReportDao.queryCheckedResultStatisticsByDay(code, param, businessTypeChecked));
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findCheckedResultMaterialModelComparison(String type, String dateType, String startTime, String endTime, String code, String mainCabCode, String param,Integer businessTypeChecked) {
        HashMap hm = new HashMap();
        switch (businessTypeChecked){
            case 2:
                hm.put("title","报修物料占比<盘验后>");
                break;
            case 3:
                hm.put("title","报废物料占比<盘验后>");
                break;
            default:
                break;
        }

        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryCheckedResultMC(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode,businessTypeChecked));
                hm.put("totalSum",workshopReportDao.queryCheckedResultTotal(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode,businessTypeChecked));
//                if (businessTypeChecked==2){
                    hm.put("totalSumOne",workshopReportDao.queryRMMCTotalOne(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode,businessTypeChecked));
//                }
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryCheckedResultMC(startWeekDateTime,endWeekDateTime,code,param,mainCabCode,businessTypeChecked));
                hm.put("totalSum",workshopReportDao.queryCheckedResultTotal(startWeekDateTime,endWeekDateTime,code,param,mainCabCode,businessTypeChecked));
//                if (businessTypeChecked==2){
                    hm.put("totalSumOne",workshopReportDao.queryRMMCTotalOne(startWeekDateTime,endWeekDateTime,code,param,mainCabCode,businessTypeChecked));
//                }
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryCheckedResultMC(startMonthDateTime,endMonthDateTime,code,param,mainCabCode,businessTypeChecked));
                hm.put("totalSum",workshopReportDao.queryCheckedResultTotal(startMonthDateTime,endMonthDateTime,code,param,mainCabCode,businessTypeChecked));
//                if (businessTypeChecked==2){
                    hm.put("totalSumOne",workshopReportDao.queryRMMCTotalOne(startMonthDateTime,endMonthDateTime,code,param,mainCabCode,businessTypeChecked));
//                }
            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryCheckedResultMC(start,end,code,param,mainCabCode,businessTypeChecked));
            hm.put("totalSum",workshopReportDao.queryCheckedResultTotal(start,end,code,param,mainCabCode,businessTypeChecked));
//            if (businessTypeChecked==2){
                hm.put("totalSumOne",workshopReportDao.queryRMMCTotalOne(start,end,code,param,mainCabCode,businessTypeChecked));
//            }

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);

    }

    @Override
    public JsonResult findLostResultMaterialModelComparison(String type, String dateType, String startTime, String endTime, String code, String mainCabCode, String param, Integer businessType) {
        HashMap hm = new HashMap();
        hm.put("title","报失物料占比");

        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryLostResultMC(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode,businessType));
                hm.put("totalSum",workshopReportDao.queryLostResultTotal(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode,businessType));

            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryLostResultMC(startWeekDateTime,endWeekDateTime,code,param,mainCabCode,businessType));
                hm.put("totalSum",workshopReportDao.queryLostResultTotal(startWeekDateTime,endWeekDateTime,code,mainCabCode,businessType));

            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryLostResultMC(startMonthDateTime,endMonthDateTime,code,param,mainCabCode,businessType));
                hm.put("totalSum",workshopReportDao.queryLostResultTotal(startMonthDateTime,endMonthDateTime,code,mainCabCode,businessType));

            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryLostResultMC(start,end,code,param,mainCabCode,businessType));
            hm.put("totalSum",workshopReportDao.queryLostResultTotal(start,end,code,mainCabCode,businessType));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findMissMaterialCostCenter(String type, String dateType, String startTime, String endTime, String code, String mainCabCode, String param) {
        HashMap hm = new HashMap();
        hm.put("title","成本中心");

        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.findMissMaterialCostCenterList(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode,param));
                hm.put("totalSum",workshopReportDao.findMissMaterialCostCenter(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode));

            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.findMissMaterialCostCenterList(startWeekDateTime,endWeekDateTime,code,mainCabCode,param));
                hm.put("totalSum",workshopReportDao.findMissMaterialCostCenter(startWeekDateTime,endWeekDateTime,code,mainCabCode));

            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.findMissMaterialCostCenterList(startMonthDateTime,endMonthDateTime,code,mainCabCode,param));
                hm.put("totalSum",workshopReportDao.findMissMaterialCostCenter(startMonthDateTime,endMonthDateTime,code,mainCabCode));

            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.findMissMaterialCostCenterList(start,end,code,param,mainCabCode));
            hm.put("totalSum",workshopReportDao.findMissMaterialCostCenter(start,end,code,mainCabCode));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }



    @Override
    public JsonResult findLostResultStatisticsByDay( String code, String param,Integer businessType) {
        HashMap hm = new HashMap();
        hm.put("title","报失统计(按天)");
        List list = new ArrayList();

        list.addAll(workshopReportDao.queryLostResultStatisticsByDay(code, param,businessType));
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findLostResultStatistics(String type, String dateType, String startTime, String endTime, String code, String mainCabCode, String param,Integer businessType) {
        HashMap hm = new HashMap();
        hm.put("title","报失统计");
        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryLostResultStatistics(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,param,mainCabCode,businessType));
            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryLostResultStatistics(startWeekDateTime,endWeekDateTime,code,param,mainCabCode,businessType));
            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryLostResultStatistics(startMonthDateTime,endMonthDateTime,code,param,mainCabCode,businessType));
            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryLostResultStatistics(start,end,code,param,mainCabCode,businessType));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findLostResultByCreator(String type, String dateType, String startTime, String endTime, String code, String mainCabCode, Integer businessType) {
        HashMap hm = new HashMap();
        hm.put("title","报失物料(按人员)");
        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryLostResultByCreator(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode,businessType));
                hm.put("totalSumOne",workshopReportDao.queryLostResultByCreatorTotalOne(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode,businessType));

            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryLostResultByCreator(startWeekDateTime,endWeekDateTime,code,mainCabCode,businessType));
                hm.put("totalSumOne",workshopReportDao.queryLostResultByCreatorTotalOne(startWeekDateTime,endWeekDateTime,code,mainCabCode,businessType));

            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryLostResultByCreator(startMonthDateTime,endMonthDateTime,code,mainCabCode,businessType));
                hm.put("totalSumOne",workshopReportDao.queryLostResultByCreatorTotalOne(startMonthDateTime,endMonthDateTime,code,mainCabCode,businessType));

            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryLostResultByCreator(start,end,code,mainCabCode,businessType));
            hm.put("totalSumOne",workshopReportDao.queryLostResultByCreatorTotalOne(start,end,code,mainCabCode,businessType));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult findLostResultByDevice(String type, String dateType, String startTime, String endTime, String code, String mainCabCode, Integer businessType) {
        HashMap hm = new HashMap();
        hm.put("title","报失物料(按设备)");
        List list = new ArrayList();

        dateTimeByDateType(dateType);//获取时间

        if(StringUtils.isNotBlank(type)){

            if(type.equals("0")){ // 日
                list.addAll(workshopReportDao.queryLostResultByDevice(FindDateStatusUtil.dayUtil().get(0),FindDateStatusUtil.dayUtil().get(1),code,mainCabCode,businessType));

            }else if(type.equals("1")){ // 周
                list.addAll(workshopReportDao.queryLostResultByDevice(startWeekDateTime,endWeekDateTime,code,mainCabCode,businessType));

            }else if(type.equals("2")){ // 月
                list.addAll(workshopReportDao.queryLostResultByDevice(startMonthDateTime,endMonthDateTime,code,mainCabCode,businessType));

            }

        }
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");

            list.addAll(workshopReportDao.queryLostResultByDevice(start,end,code,mainCabCode,businessType));

        }
        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }
}
